if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
    MESSAGE (FATAL_ERROR "in-tree build not allowded")
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})

CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
PROJECT (iotkit-embedded-V2.3.0 C)

SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
SET (CMAKE_C_FLAGS " -Iexamples -Iexamples/linkkit -Itests -Os -Wall -fPIC")

IF (WIN32)
    SET (CMAKE_EXE_LINKER_FLAGS "-L${PROJECT_SOURCE_DIR}/prebuilt/win7/libs")
ENDIF (WIN32)

MESSAGE ("---------------------------------------------------------------------")
MESSAGE ("Project Name              : " ${PROJECT_NAME})
MESSAGE ("Source Dir                : " ${PROJECT_SOURCE_DIR})
MESSAGE ("Binary Dir                : " ${PROJECT_BINARY_DIR})
MESSAGE ("System Processor          : " ${CMAKE_SYSTEM_PROCESSOR})
MESSAGE ("System Platform           : " ${CMAKE_SYSTEM})
MESSAGE ("C Compiler                : " ${CMAKE_C_COMPILER})
MESSAGE ("Executable Dir            : " ${EXECUTABLE_OUTPUT_PATH})
MESSAGE ("Library Dir               : " ${LIBRARY_OUTPUT_PATH})
MESSAGE ("SDK Version               : " V2.3.0)
MESSAGE ("")

IF (WIN32)
    MESSAGE ("Building on WINDOWS ...")
ELSE (WIN32)
    MESSAGE ("Building on LINUX ...")
ENDIF (WIN32)
MESSAGE ("---------------------------------------------------------------------")

ADD_DEFINITIONS (-DDLL_IOT_EXPORTS)

ADD_DEFINITIONS (-DAWSS_DISABLE_ENROLLEE)
ADD_DEFINITIONS (-DAWSS_DISABLE_REGISTRAR)
ADD_DEFINITIONS (-DAWSS_SUPPORT_ADHA)
ADD_DEFINITIONS (-DAWSS_SUPPORT_AHA)
ADD_DEFINITIONS (-DAWSS_SUPPORT_APLIST)
ADD_DEFINITIONS (-DAWSS_SUPPORT_PHONEASAP)
ADD_DEFINITIONS (-DAWSS_SUPPORT_ROUTER)
ADD_DEFINITIONS (-DAWSS_SUPPORT_SMARTCONFIG)
ADD_DEFINITIONS (-DAWSS_SUPPORT_SMARTCONFIG_WPS)
ADD_DEFINITIONS (-DAWSS_SUPPORT_ZEROCONFIG)
ADD_DEFINITIONS (-DCOAP_SERV_MULTITHREAD)
ADD_DEFINITIONS (-DCONFIG_HTTP_AUTH_TIMEOUT=5000)
ADD_DEFINITIONS (-DCONFIG_MID_HTTP_TIMEOUT=5000)
ADD_DEFINITIONS (-DCONFIG_GUIDER_AUTH_TIMEOUT=10000)
ADD_DEFINITIONS (-DDEVICE_MODEL_ENABLED)
ADD_DEFINITIONS (-DDEV_BIND_ENABLED)
ADD_DEFINITIONS (-DFORCE_SSL_VERIFY)
ADD_DEFINITIONS (-DMQTT_COMM_ENABLED)
ADD_DEFINITIONS (-DMQTT_DIRECT)
ADD_DEFINITIONS (-DOTA_ENABLED)
ADD_DEFINITIONS (-DOTA_SIGNAL_CHANNEL=1)
ADD_DEFINITIONS (-DSUPPORT_TLS)
ADD_DEFINITIONS (-DWIFI_PROVISION_ENABLED)
ADD_DEFINITIONS (-D_PLATFORM_IS_HOST_)

ADD_SUBDIRECTORY (src/infra/utils)
ADD_SUBDIRECTORY (src/infra/log)
ADD_SUBDIRECTORY (src/infra/system)
ADD_SUBDIRECTORY (src/sdk-impl)
ADD_SUBDIRECTORY (src/protocol/mqtt)
ADD_SUBDIRECTORY (src/services/ota)
ADD_SUBDIRECTORY (src/services/linkkit/cm)
ADD_SUBDIRECTORY (src/services/linkkit/dm)
ADD_SUBDIRECTORY (src/services/linkkit/dev_reset)
ADD_SUBDIRECTORY (src/protocol/coap/local)
ADD_SUBDIRECTORY (src/services/awss)
ADD_SUBDIRECTORY (src/services/dev_diagnosis)
ADD_SUBDIRECTORY (src/services/dev_bind)

ADD_SUBDIRECTORY (src/ref-impl/hal)
ADD_SUBDIRECTORY (examples)
ADD_SUBDIRECTORY (src/ref-impl/tls)

ADD_LIBRARY (iot_sdk SHARED
    $<TARGET_OBJECTS:iot_utils>
    $<TARGET_OBJECTS:iot_log>
    $<TARGET_OBJECTS:iot_system>
    $<TARGET_OBJECTS:sdk_impl>
    $<TARGET_OBJECTS:iot_mqtt>
    $<TARGET_OBJECTS:iot_ota>
    $<TARGET_OBJECTS:iot_cm>
    $<TARGET_OBJECTS:iot_dm>
    $<TARGET_OBJECTS:iot_reset>
    $<TARGET_OBJECTS:iot_coap_local>
    $<TARGET_OBJECTS:iot_awss>
    $<TARGET_OBJECTS:iot_dev_diagnosis>
    $<TARGET_OBJECTS:iot_bind>
)
if(WIN32)
    TARGET_LINK_LIBRARIES (iot_sdk ws2_32)
endif(WIN32)

TARGET_LINK_LIBRARIES (iot_sdk iot_hal)

SET (LIBRARY_OUTPUT_PATH ./out)
